from typing import List


class Solution:
    def search(self, nums: List[int], target: int) -> int:
        left, right = 0, len(nums) - 1
        while left < right:
            mid = left + right + 1 >> 1
            if nums[mid] >= nums[0]:
                left = mid
            else:
                right = mid - 1
        if target >= nums[0]:
            left = 0
        else:
            left = right + 1
            right = len(nums) - 1
        while left < right:
            mid = left + right >> 1
            if target <= nums[mid]:
                right = mid
            else:
                left = mid + 1
        if target == nums[right]:
            return right
        else:
            return -1
